package prickworlds.game;

import prickworlds.physics.RectRigidBody;
import prickworlds.physics.RigidBody;
import prickworlds.physics.RigidBodyListener;

/**
 * Base class for every object that is subject to the laws of physics
 * 
 * @author Faruk Acibal, Richard Dziambor, Christian Holzreuter, Nicolas Winkler
 * 
 */
public abstract class SolidObject extends GameObject implements
		RigidBodyListener {
	private RigidBody hitbox;

	public SolidObject(float posX, float posY) {
		super(posX, posY);
		setHitbox(new RectRigidBody());
	}

	public void update() {
		hitbox.setPos(posX, posY);
	}

	public RigidBody getHitbox() {
		return hitbox;
	}

	public void setHitbox(RigidBody r) {
		hitbox = r;
		hitbox.addRigidBodyListener(this);
	}

	public void processCollision(SolidObject b) {
		hitbox.setPos(posX, posY);
		hitbox.processCollision(b.getHitbox());
	}

	@Override
	public void rigidBodyUpdated() {
		posX = hitbox.getPosX();
		posY = hitbox.getPosY();
	}
}
